/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kythuatxml;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.Node;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 *
 * @author anh_yeu_em_nhieu_lam
 */
public class OpenXMLDocument {

    public OpenXMLDocument() {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse("data/MyXML.xml");
            NodeList nodelist = doc.getElementsByTagName("Item");
            for(int i = 0;i<nodelist.getLength();i++){
                System.out.print("Node thu " + i +":\n");
                NodeList nodechild = nodelist.item(i).getChildNodes();
                for(int j=0;j<nodechild.getLength();j++){
                    if(nodechild.item(j).getNodeType() == Node.ELEMENT_NODE)
                    {
                        System.out.print(nodechild.item(j).getNodeName() + " :");
                        System.out.print(nodechild.item(j).getTextContent()+"\n");
                    }
                }
            }

        } catch (SAXException ex) {
            Logger.getLogger(OpenXMLDocument.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(OpenXMLDocument.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(OpenXMLDocument.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    public static void main(String arg[]){
            new OpenXMLDocument();
    }
}
/*
Node thu 0:
Name :San pham 1
Description :Day la san pham 1
Node thu 1:
Name :San pham 2
Description :Day la san pham 2
Node thu 2:
Name :San pham 3
Description :Day la san pham 3
 * */